/******************************************************************************
 * XWiki.JavaScriptExtension[2]: onLoadExhibit() -- called from macro 
 * #exhibit_create() to initialize Exhibit database from JSON 'data' and 
 * dynamically build UI.
 * Copyright (C) 2009-2011, Niels Mayer. All Rights Reserved. http://nielsmayer.com
 ******************************************************************************/
function onLoadExhibit() {
  SimileAjax.jQuery(document).ready(function() {
    addExhibitInterceptorsAndOverides();
    var fDone = function() {
      window.exhibit = Exhibit.create();
//    window.exhibit.createBusyIndicator();
      window.exhibit.configureFromDOM();
    };
    try {
      var s = Exhibit.getAttribute(document.body, "ondataload");
      if (s != null && typeof s == "string" && s.length > 0) {
	fDone = function() {
	  var f = eval(s);
	  if (typeof f == "function") {
	    f.call();
	  }
	}
      }
    } catch (e) { /* silent */ };
    var fLoadSubmissions = function() {
      window.database.loadSubmissionLinks(fDone);
    };
    window.database = Exhibit.Database.create();
    window.database.loadData(data);
    window.database.loadDataLinks(fLoadSubmissions);
  });
}
